<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<input type="file" name="picFieldName" id="picFieldId" onchange="uploadPic(this)" />
	</body>
</html>
<!-- oss 上传文件 JavaScript 库 -->
<script src="http://gosspublic.alicdn.com/aliyun-oss-sdk-4.4.4.min.js"></script>
<script>
    var client = new OSS.Wrapper({
        region : 'oss-cn-hangzhou',
        accessKeyId : 'LTAILUlTg4vCd0xp',
        accessKeySecret : 'iZCIFGVD5P99Ydr7pZJcB5YRIv9nA0',
        bucket : 'mobao-app',
        secure:true
    });
    function uploadPic(obj){
        var file=obj.files[0];//获取文件流
        var val= obj.value;
        var suffix = val.substr(val.indexOf("."));
        var storeAs = "video/"+timestamp()+suffix;
        console.log(file.name + ' => ' + storeAs);
        client.multipartUpload(storeAs, file).then(function (result) {
			console.log(result)
        }).catch(function (err) {
            console.log(err);
        });
    }


    /**
     * 生成文件名
     * @returns
     */
    function timestamp(){
        var time = new Date();
        var y = time.getFullYear();
        var m = time.getMonth()+1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        console.log(y);
        return ""+y+add0(m)+add0(d)+add0(h)+add0(mm)+add0(s);
    }
    function add0(m){
        return m<10?'0'+m : m;
    }
</script>